package com.buss.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
 * Created by cp on 2017/1/13.
 */
public class OSProperties {

    public static String getUrlRepo(){
        //判断系统
        String repo = "";
        String osName = System.getProperty("os.name");
        if (osName.toLowerCase().contains("mac")
                    || osName.toLowerCase().contains("windows")) {
            repo = Constant.repo;
        } else {
            String filePath = Constant.application.getString("repo_file_linux");
            repo = txt2String(filePath);
        }
        return repo;
    }

    /**
     * 读取txt文件的内容
     * @param filePath 想要读取的文件路径
     * @return 返回文件内容
     */
    public static String txt2String(String filePath){
        StringBuilder result = new StringBuilder();
        try{
            File file = new File(filePath);
            //构造一个BufferedReader类来读取文件
            BufferedReader br = new BufferedReader(new FileReader(file));
            result.append(br.readLine()); //使用readLine方法，读一行
            br.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return result.toString();
    }
}
